﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using System.IO;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class CertificateFile
    {
        public static readonly String ElementName = "CertificateFile";

        public String DataPath { get; private set; }
        public String Format { get; private set; }
        public String Password { get; private set; }

        public CertificateFile(String dataPath, String format, String password)
        {
            this.DataPath = dataPath;
            this.Format = format;
            this.Password = password;
        }
        public String CreateText()
        {
            var ns = XNamespace.Get("http://schemas.microsoft.com/windowsazure");
            var doc = new XDocument();
            var root = new XElement(ns.GetName(ElementName));
            doc.Add(root);
            root.Add(new XElement(ns.GetName("Data"), Convert.ToBase64String(File.ReadAllBytes(this.DataPath))));
            root.Add(new XElement(ns.GetName("CertificateFormat"), this.Format));
            root.Add(new XElement(ns.GetName("Password"), this.Password));
            return doc.ToString();
        }
    }
}
